package LeetCode;

public class LC_112_PathSum {

    public static void main(String[] args) {

    }

    class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    public class Solution {
        private boolean checkPathSum(TreeNode root, int sum, int now) {
            if (root == null) return false;
            now += root.val;
            if (root.left == null && root.right == null) return sum == now;
            return checkPathSum(root.left, sum, now) || checkPathSum(root.right, sum, now);
        }

        public boolean hasPathSum(TreeNode root, int sum) {
            return root != null && checkPathSum(root, sum, 0);
        }
    }
}